<?php
session_start();
include_once('../../admin/php/includes/definer.php');
include_once(INC.'resources/securimage/securimage.php');
$securimage = new Securimage();
if ($securimage->check($_POST['captcha_code']) == false) { //chequeo que el captcha sea correcto
    header('location: '.$_SERVER['HTTP_REFERER'].'#error');
    exit();
}
include_once(INC.'admin/php/bootstrap.php');
include_once(INC.'admin/php/clases/class.phpmailer.php');

$prod = Doctrine::getTable('producto')->find($_POST['id']);

$contenido = '<p><strong>Nombre:</strong> '.htmlentities($_POST['nombre']).'</p>';
$contenido .= '<p><strong>Email:</strong> '.$_POST['email'].'</p>';
$contenido .= '<p><strong>Producto:</strong> <a href="'.URL.'producto/'.$prod->iur.'">'.htmlentities($prod->titulo).'</a></p>';
$contenido .= '<p><strong>Consulta:</strong><br />'.nl2br(htmlentities($_POST['mensaje']));

$mail = new phpmailer();
$mail->PluginDir = 'include/';
$mail->Mailer = "smtp";
$mail->Host = "smtp.chatarraonline.com.ar";
$mail->SMTPAuth = true;
$mail->Username = "no-reply@chatarraonline.com.ar"; 
$mail->Password = "ordeno2552";
$mail->From = "no-reply@chatarraonline.com.ar";
$mail->FromName = "Consultas online";
$mail->Timeout=30;
$mail->AddAddress('info@chatarraonline.com');
$mail->IsHTML(true);
$mail->Subject = 'Consultas online';
$mail->Body = $contenido;
$exito = $mail->Send();

$intento=1; 
while ((!$exito) && ($intento <= 2)) {
    sleep(3);
    $exito = $mail->Send();
    $intento++;	
}

header('location: '.$_SERVER['HTTP_REFERER'].'#success');
?>
